<template>

	<view scroll-y class="order-list" @scrolltolower="onreachBottom">
	
		<u-row class="item" 
		:class="{'pending':drp.status==0,'success':drp.status==1,'complete':drp.status==2,'cancel':drp.status==3}" 
		gutter="16" v-for="drp in drp_list" >
			<u-col span="4">
				<view class="avatar" >
					<text>金额:{{drp.total}}￥</text>				
				</view>
	
			</u-col>
			<u-col span="4">
				<view class="rate" >
					<text>比例:{{drp.rate}}%</text>							
				</view>
				
			</u-col>
			<u-col span="4">
				<view class="order-fenxiao" >
					<view class="order"> {{drp.status_text}} </view>
				</view>
	
			</u-col>
			
		</u-row>
		<view class="nothing" v-if="drp_list.length==0">
			当前没有分销订单记录
		</view>
		<view class="bottom-button" >
			<view class='cash-text' >当前可提现金额：<text>{{cash_total}}￥</text></view>
			<view class="cash-out">
				<u-button @click="cash_out" type="primary">提现</u-button>
			</view>
			
		</view>

		<u-toast ref="uToast" />
	</view>
</template>

<script>
	
	const appInstance = getApp();
	export default {
		data() {
			return {
				cover_bg	: '',
				drp_list	: [],
				cash_total	: 0
			}
		},
		onLoad(options) {
			var that = this;
			var host = appInstance.globalData.api_host.split('/app')[0];
			this.cover_bg = appInstance.globalData.customer_bg_img;
			appInstance.globalData.checkUserStatus();
			this.init(options);
		},
		onPullDownRefresh() {
			this.init();
			setTimeout(function () {
			    uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
	
			init: function(options) {
	
				this.get_list();
			},
	
			get_list: function() {
				var t = this;
				var url = '&r=distribution.distribution';
	
				appInstance.globalData.request(url, {
					m: 'sm_shop_plugin_distribution'
				}, 'GET', function(res) {
					t.drp_list = res.data.list;
					t.cash_total = res.data.total.total;
				});
			},
	
			cash_out:function(){
				
				var t = this;
				var url = '&r=distribution.apply_cash';
					
				appInstance.globalData.request(url, {
					m: 'sm_shop_plugin_distribution'
				}, 'GET', function(res) {
					if(res.data.status ){
						t.$refs.uToast.show({
							title:  res.data.description,
							type: 'error'
						})
					}else{
						t.$refs.uToast.show({
							title:  '申请成功',
							type: 'success',
							callback:function(){
								t.get_list();
							}
						})
					}
					
				});
				
			}
			
		}
	}
</script>

<style lang="less">
	@import './distributor.less';
</style>
